/**
 * common methods for db operations
 */
const logger = require('../config/logger');

class dbhelper {
    static async insertToCollection(Model, insertList) {
        let res = await Model.collection.insertMany(insertList);
        if (!res) {
            logger.error('文档插入出错');
        }
        return !!res;
    }

    static async updateCollection(Model, conditions, doc) {
        let res = await Model.update(conditions, doc).exec();
        if (!res) {
            logger.error('文档更新出错');
        }
        return !!res;
    }

    static async removeDocuments(Model, conditions) {
        let res = await Model.remove(conditions);
        if (!res) {
            logger.error('文档删除出错');
        }
        return !!res;
    }
}

module.exports = dbhelper;
